package com.zhangtao.note.util;

import com.alibaba.fastjson.JSON;
import com.zhangtao.note.po.NoteType;
import com.zhangtao.note.vo.ResultInfo;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

public class JsonUtil {
    public static void toJson(HttpServletResponse resp , Object result){
        try {
            resp.setContentType("application/json;charset=UTF-8");
            //得到字符输出流
            PrintWriter out = resp.getWriter();
            //通过阿里巴巴的fastjson方法将对象转为json格式字符串
            String json = JSON.toJSONString(result);
            out.write(json);
            out.close();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
